package cn.itsource.hrm.holder;

import cn.itsource.hrm.vo.UserContextInfo;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * UserContextInfo类持有者
 */
public class UserContextInfoHolder {
    private static UserContextInfo userContextInfo;

    //获取UserContextInfo
    public static UserContextInfo  getUserContextInfo(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        String userContextInfoStr = (String) authentication.getPrincipal(); //Username-yaosang110
        UserContextInfo userContextInfo = JSONObject
                .parseObject(userContextInfoStr, UserContextInfo.class);
        return  userContextInfo;
    }
}
